package pwd.allen.listener;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import org.springframework.stereotype.Component;

/**
 * @author 门那粒沙
 * @create 2021-09-04 17:55
 **/
@Component
public class NacosListener {

    /**
     * 会把配置组件注入进来，config-center
     */
    @NacosInjected
    private ConfigService configService;

    /**
     * 监听配置变更
     *
     * 等同于
     * configService.addListener(DATA_ID, DEFAULT_GROUP, new AbstractListener())
     * @param data
     */
    @NacosConfigListener(dataId = "myData", groupId = "DEFAULT_GROUP", converter = DataConfigConverter.class)
    public void onMessage(Data data) {
        System.out.println(data);
    }
}
